@extends('admin.base')
@section('title','发送消息')
@section('header','发送消息')
@section('content')
    <fieldset class="layui-elem-field">
        <div class="layui-field-box">
            <span class="layui-breadcrumb" lay-separator=">>">
                <a class="layui-btn-sm" href="" style="cursor:pointer;" ><cite>添加消息通知</cite></a>;
            </span>
        </div>
    </fieldset>
    <form class="layui-form" method="post" action="/admin/information/store">
        @csrf
        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
                <input type="radio" name="type" value="1"  lay-filter="type" title="所有用户" checked="">
                <input type="radio" name="type" value="2"  lay-filter="type" title="单独用户">
            </div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>

        <div class="layui-form-item" id="users" style="display: none;">
            <label class="layui-form-label">用户ID:</label>
            <div class="layui-input-block">
                <input type="text" name="uid" placeholder="请输入用户ID"
                       autocomplete="off"
                       value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标题:</label>
            <div class="layui-input-block">
                <input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off"
                       value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">内容:</label>
            <div class="layui-input-block">
                <textarea id="demo" style="display: none;" name="content"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
@endsection
@section('js')
    <script>
        layui.use('layedit', function(){
            var layedit = layui.layedit;
            layedit.build('demo'); //建立编辑器
        });

        layui.use(['layedit','form'],
            function() {
                var layedit = layui.layedit;
                layedit.set({
                    uploadImage: {
                        url: '/admin/notice/upload',
                        type: 'post'
                    }
                });
                var index = layedit.build('demo'); //建立编辑器
                var form = layui.form;
                var layedit = layui.layedit;
                //监听提交
                form.on('submit(formDemo)', function(data){
                    var aa = layedit.getContent(index);
                    data.field.content = aa;
                    layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){
                        ajax("{{url('admin/information/store')}}",data.field,function(data){
                            layer.close();
                            layer.closeAll();
                            layer.msg(data.msg);
                            if(data.code == 1){
                                location.href = '/admin/information/index';
                            }
                        });
                    });
                    return false;
                });

                //绑定单选
                form.on('radio(type)', function (data) {
                    if(data.value == 1){
                        $("#users").css('display','none');
                    }else{
                        $("#users").css('display','block');
                    }
                });
            });



    </script>
@endsection
